<?php

namespace app\admin\service\system;

use app\admin\model\Admin;
use app\admin\model\UploadFiles;
use think\facade\Db;
use app\admin\service\BaseService;
class UploadService extends BaseService
{

    /**
     * 获取列表
     * @param $data
     * @return mixed
     */
    public function getList($param)
    {
        $model = new UploadFiles();
        $admin = new Admin();
        $user = new Admin();
        $searchFields = ['file_name', 'extension', 'url'];//模糊搜索
        $search = ['app','class_id'];//精准搜索
        $fields = [];//查询字段
        $list = $this->paginateWithSearch($model, $param, $fields, $searchFields, $search ,'created_at','desc');
        foreach ($list['data'] as $v){
            if ($v['app'] === 2) {
                $v['user_id'] = $admin->where('id',$v['user_id'])->value('username');
            } else {
                $v['user_id'] = $user->where('id',$v['user_id'])->value('phone');
            }
        }
        return success($list);
    }
    /**
     * 添加
     * @param $data
     * @return mixed
     */
    public function Add($data)
    {
      return alert(500, 'error', null);
    }
    /**
     * 编辑
     * @param $id
     * @param $data
     * @return mixed
     */
    public function Edit($id, $data)
    {
      return alert(500, 'error', null);
    }
    /**
     * 删除
     * @param $ids
     * @return mixed
     */
    public function Del($ids)
    {
      return alert(500, 'error', null);
    }
}
